import { View, Text, Image, Textarea } from "@tarojs/components";
import Taro, { useLoad, useUnload } from "@tarojs/taro";
import { Button, Cell, CellGroup, Dialog, Empty, NavBar, Picker } from "@nutui/nutui-react-taro";
import { Share, More, Cart, ArrowLeft, Close } from '@nutui/icons-react-taro'
import { c } from "../../common/index.js";
import { useEffect, useState } from "react";
import { getParams, navigateTo } from "../../common/_.js";

import { selectEnts, selectExamDetail, startExam } from "../../api/ceshi.js";
import SelectItem from "../../components/selectItem/index.jsx";
import InputItem from "../../components/inputItem/index.jsx";
import dayjs from "dayjs";
import { getStore } from "../../utils/localStore.js";
import { addApply } from "../../api/apply.js";
import { selectDict, selectDictById, selectDictByParentId, selectDicts } from "../../api/system.js";
import { getGlobalData, getSystemEnumValue, initGlobalData } from "../../utils/globalData.js";
import useNavInfo from "../../hooks/useNavInfo.js";
import NavTab from "../../components/navTab/index.jsx";

import { XfVoiceDictation } from '@muguilin/xf-voice-dictation';

import "./index.scss";

export default function Voice(props) {



  const [content, setContent] = useState('')


    let times = null;
    const xfVoice = new XfVoiceDictation({
        APPID: '5f23e950',
        APISecret: 'd35c1c14322ec807e4917d4ef6fc1dfa',
        APIKey: '2eb31b8b794cfae019e4e206949a6d2b',

        // webSocket请求地址 非必传参数，默认为：wss://iat-api.xfyun.cn/v2/iat
        // url: '',

        // 监听录音状态变化回调
        onWillStatusChange: function (oldStatus, newStatus) {
            // 可以在这里进行页面中一些交互逻辑处理：注：倒计时（语音听写只有60s）,录音的动画，按钮交互等！
            console.log('识别状态：', oldStatus, newStatus);
        },

        // 监听识别结果的变化回调
        onTextChange: function (text) {
            // 可以在这里进行页面中一些交互逻辑处理：如将文本显示在页面中
            console.log('识别内容：', text)
            setContent(text)

            // 如果3秒钟内没有说话，就自动关闭（60s后也会自动关闭）
            if (text) {
                clearTimeout(times);
                times = setTimeout(() => {
                    stopFn();
                }, 3000);
            };
        },

        // 监听识别错误回调
        onError: function (error) {
            console.log('错误信息：', error)
        }
    });




    useEffect(() => {
        console.log("eest")
    }, [])

    const startFn = () => {
        setVoiceVisible(true)
        xfVoice.start();
    }

    const stopFn = () => {
        xfVoice.stop();
        setVoiceVisible(false)
    }

    const [voiceVisible, setVoiceVisible] = useState(false)




  

  return (
    <View className="wrap" onclick={() => pageClick()}>
      <View onClick={() => startFn()} >
        <Text>start</Text>
      </View>
      <View onClick={() => startFn()} >
        <Text>start</Text>
      </View>
      <View onClick={() => startFn()} >
        <Text>start</Text>
      </View>
      <View onClick={() => startFn()} >
        <Text>start</Text>
      </View>

      <View onClick={() => stopFn()}>
        <Text>stopFn</Text>
      </View>
    </View>
  );
}
